package alg;

import java.util.ArrayList;
import data.Sorter;
import data.Student;
import data.StudentDataReader;

/**
 * A student wrapper class - processes the list of students for use in the algorithm.
 * @author Frans Honig, Maxime Serrano, Raphael Townshend
 */
public class StudentProcessor
{
	/**
	 * Reads in the list of students from the default file and then returns the generated <code>ArrayList</code>.
	 * @return An ArrayList of all student data.
	 */
	public static ArrayList<Student> generateStudentList()
	{
		StudentDataReader studentData = new StudentDataReader();
		studentData.read();
		ArrayList<Student> students = studentData.getAsList();
		//sortByClasses(students);
		return students;
	}
	
	/**
	 * Reads in the list of students from the default file and then returns the generated <code>ArrayList</code>.
	 * @return An ArrayList of all student data.
	 */
	public static ArrayList<Student> generateStudentList(String fileName)
	{
		StudentDataReader studentData = new StudentDataReader(fileName);
		studentData.read();
		ArrayList<Student> students = studentData.getAsList();
		testSort(students);
		sortByClasses(students);
		return students;
	}
	
	/**
	 * Sorts the list by first choice numbers.
	 * @param list The list to sort.
	 */
	public static void sortByClasses(ArrayList<Student> list)
	{
		for (int i = 0; i < list.size(); i++)
		{
			for (int j = 0; j < list.size() - i - 1; j++)
			{
				if (list.get(j).getClassWeight() > list.get(j + 1).getClassWeight())
				{
					Student temp = list.get(j);
					list.set(j, list.get(j + 1));
					list.set(j + 1, temp);
				}
			}
		}
	}
	
	/**
	 * Sorts the students using the default compareTo method.
	 * @param students The student ArrayList to be sorted.
	 */
	public static void testSort(ArrayList<Student> students)
	{
		Sorter<Student> ss = new Sorter<Student>();
		ss.sort(students);
	}
	
	/**
	 * Sorts the students using the compareToDate method.
	 * @param students The student ArrayList to be sorted.
	 */
	public static void testDateSort(ArrayList<Student> students)
	{
		Sorter<Student> ss = new Sorter<Student>();
		ss.dateSort(students);
	}
	
	/**
	 * Prints out the list.
	 * @param students The list of students to be printed.
	 */
	public static void printList(ArrayList<Student> students)
	{
		for (int i = 0; i < students.size(); i++)
		{
			System.out.println(students.get(i));
		}
	}
}
